#ifndef _PD_TYPES_H_
#define _PD_TYPES_H_

typedef struct PD_vect2 {
	double x, y;
} PD_vect2;

typedef struct PD_vect3 {
	double x, y, z;
} PD_vect3;

typedef struct PD_rect {
	PD_vect2 topLeft;
	PD_vect2 size;
	double top() { return topLeft.y; }
	double right() { return topLeft.x + size.x; }
	double left() { return topLeft.x; }
	double bottom() { return topLeft.y + size.y; }
	double width() { return size.x; }
	double height() { return size.y; }
	void setTopLeft(double x, double y) { topLeft.x = x; topLeft.y = y; }
	void setBottomRight(double x, double y) { size.x = x - topLeft.x; size.y = y - topLeft.y; }
	void setSize(double w, double h) { size.x = w; size.y = h; }
	void setAll(double left, double top, double width, double height) { setTopLeft(left, top); setSize(width, height); }
	bool collidesWith(PD_rect &other) {
		//If collides in x direction
		if ((other.left() >= left() && other.left() <= right())
			|| (other.right() >= left() && other.right() <= right())
			|| (left() >= other.left() && left() <= other.right())
			|| (right() >= other.left() && right() <= other.right()))
		{
			//If collides in y direction also, it truly collides
			if ((other.top() >= top() && other.top() <= bottom())
				|| (other.bottom() >= top() && other.bottom() <= bottom())
				|| (top() >= other.top() && top() <= other.bottom())
				|| (bottom() >= other.top() && bottom() <= other.bottom()))
			{
				return true;
			}
		}
		return false;
	}
	//Returns positive for left overlap and negative for right overlap
	double getXOverlap(PD_rect &other) {
		double x = 0;

		//If i'm on the left (or if my left and right are surrounding the left edge of the other rect
		if (left() < other.left() && right() > other.left())
		{
			return right() - other.left();
		}
		//If i'm on the right (if my left and right are surrounging the right edge of the other
		else if (right() > other.right() && left() < other.right())
		{
			return left() - other.right();
		}
		return 0.0;
	}
};

enum PlayerSide {
	PLAYER_LEFT,
	PLAYER_RIGHT
};

enum PlayerType {
	PLAYER_HUMAN,
	PLAYER_COMPUTER
};

#endif